﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Tool.hbm2ddl;
using NHibernate.Linq;

namespace Perpus
{
    public partial class ListBuku : Form
    {
        const string konek = (@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Compaq\Documents\coba.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");

        private ISessionFactory CreateSessionFactory()
        {
            return Fluently.Configure()
                .Database(MsSqlConfiguration.MsSql2008.ConnectionString(konek))
                .Mappings(m => m.FluentMappings.AddFromAssemblyOf<BukuMap>())
                .BuildSessionFactory();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var factory = CreateSessionFactory();

            using (var session = factory.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    var book = new Buku
                    {
                        kode_buku = int.Parse(textBox1.Text),
                        id_penerbit = int.Parse(textBox2.Text),
                        nama_buku = textBox3.Text,
                        denda = int.Parse( textBox4.Text),
                        status = textBox5.Text
                        //Name = txtCategoryName.Text,
                        //Description = txtCategoryDescription.Text
                    };

                    session.Save(book);
                    transaction.Commit();
                }
            }   
        }
     
    }
}
